/* eslint-disable */
import axios from 'axios'
export async function getList(params) {
    const searchParams = new URLSearchParams();
    
    // 添加基本参数
    searchParams.append('page', params.page);
    searchParams.append('pageSize', params.pageSize);
    searchParams.append('start', params.start);
    searchParams.append('end', params.end);
    
    // 添加多个genres参数
    if (params.genres && params.genres.length > 0) {
        params.genres.forEach(genre => {
            searchParams.append('genres', genre);
        });
    }
    
    // 添加多个keys参数
    if (params.keys && params.keys.length > 0) {
        params.keys.forEach(key => {
            searchParams.append('keys', key);
        });
    }

    console.log(searchParams.toString());
    
    const response = await axios.get('http://localhost:8080/tracks', {
        params: searchParams,
        headers: {
            Accept: 'application/json',
        }
    });
    console.log(response.data.data.list);

    return response.data.data;
}


export async function getGenresList () {
    const response = await axios.get('http://localhost:8080/genres', {
      headers: {
        Accept: 'application/json',
      }
    })
    console.log(response.data.data.list)

    return response.data.data.list
}

export async function getDiaoShi () {
    const response = await axios.get('http://localhost:8080/keys', {
      headers: {
        Accept: 'application/json',
      }
    })
    console.log(response.data.data.list)

    return response.data.data.list
}

export async function getKeyFenBu(params) {
  const searchParams = new URLSearchParams();
  
  // 添加基本参数
  searchParams.append('start', params.start);
  searchParams.append('end', params.end);

  
  // 添加多个genres参数
  if (params.genres && params.genres.length > 0) {
      params.genres.forEach(genre => {
          searchParams.append('genres', genre);
      });
  }
  
  // 添加多个keys参数
  if (params.keys && params.keys.length > 0) {
      params.keys.forEach(key => {
          searchParams.append('keys', key);
      });
  }

  console.log(searchParams.toString());
  
  const response = await axios.get('http://localhost:8080/tracks/key', {
      params: searchParams,
      headers: {
          Accept: 'application/json',
      }
  });
  console.log('调式分布11111',response.data.data.list);

  return response.data.data.list;
}

export async function getGenresFenBu(params) {
  const searchParams = new URLSearchParams();
  
  // 添加基本参数
  searchParams.append('start', params.start);
  searchParams.append('end', params.end);

  
  // 添加多个genres参数
  if (params.genres && params.genres.length > 0) {
      params.genres.forEach(genre => {
          searchParams.append('genres', genre);
      });
  }
  
  // 添加多个keys参数
  if (params.keys && params.keys.length > 0) {
      params.keys.forEach(key => {
          searchParams.append('keys', key);
      });
  }

  console.log(searchParams.toString());
  
  const response = await axios.get('http://localhost:8080/tracks/genre', {
      params: searchParams,
      headers: {
          Accept: 'application/json',
      }
  });
  console.log('流派分布11111',response.data.data.list);

  return response.data.data.list;
}

export async function getDanceFenBu(params) {
  const searchParams = new URLSearchParams();
  
  // 添加基本参数
  searchParams.append('start', params.start);
  searchParams.append('end', params.end);

  
  // 添加多个genres参数
  if (params.genres && params.genres.length > 0) {
      params.genres.forEach(genre => {
          searchParams.append('genres', genre);
      });
  }
  
  // 添加多个keys参数
  if (params.keys && params.keys.length > 0) {
      params.keys.forEach(key => {
          searchParams.append('keys', key);
      });
  }

  console.log(searchParams.toString());
  
  const response = await axios.get('http://localhost:8080/tracks/danceability', {
      params: searchParams,
      headers: {
          Accept: 'application/json',
      }
  });
  console.log('跳舞程度11111',response.data.data.list);

  return response.data.data.list;
}

export async function getPowerFenBu(params) {
  const searchParams = new URLSearchParams();
  
  // 添加基本参数
  searchParams.append('start', params.start);
  searchParams.append('end', params.end);

  
  // 添加多个genres参数
  if (params.genres && params.genres.length > 0) {
      params.genres.forEach(genre => {
          searchParams.append('genres', genre);
      });
  }
  
  // 添加多个keys参数
  if (params.keys && params.keys.length > 0) {
      params.keys.forEach(key => {
          searchParams.append('keys', key);
      });
  }

  console.log(searchParams.toString());
  
  const response = await axios.get('http://localhost:8080/tracks/danceability', {
      params: searchParams,
      headers: {
          Accept: 'application/json',
      }
  });
  console.log('强度',response.data.data.list);

  return response.data.data.list;
}